 <?php require_once ADMINVIEWPATH.'admin_header.php'; ?>
<?php require_once ADMINVIEWPATH.'admin_menu.php'; ?>
 <link href="<?= STATICURL; ?>css/bootstrap.min.css" rel="stylesheet" />
    <link id="bootstrap-rtl-link" href="" rel="stylesheet" />
    <link id="beyond-link" href="<?= STATICURL; ?>css/beyond.min.css" rel="stylesheet" type="text/css" />
    <style>
        input[type=radio] {
            position:static;
            opacity: 1;
        }
    </style>
    <div class="page-content">
     <!-- Page Breadcrumb -->
        <div class="page-breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="fa fa-home"></i>
                    <a href="/luckydog/index">首页</a>
                </li>
                <li class="">
                    <a href="/luckydog/news/index">新闻列表</a>
                </li>
                <li class="active">
                    <a href="#">题目列表</a>
                </li>
            </ul>
        </div>
        <!-- /Page Breadcrumb -->
		<?php if($newsInfo['ispublish'] == 0):?>
        <div class="table-toolbar" style="float:right;position: fixed ; top: 200px;right:230px;">
			<a  href="javascript:void(0);"  class=" btn btn-default edit_question">
				创建试题
			</a>
		</div>
		<?php endif;?>
        <div class="page-body">
            <div >
                <div id="horizontal-form">
                <div class="row">
                    <div ></div>
                    <div style="float: left; padding-left:10px;">
                        <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">设置全部答对时的积分:</div>
                        <input class="form-control" style="width:100px;" value="<?=$newsInfo['all_question_point']?>" <?php if($newsInfo['ispublish']):?>disabled="disabled"<?php endif;?>   id="all_question_point" type="text">
                    </div>
                    <div style="float: left; padding-left:10px;">
                        <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">设置全部答对时的奖金:</div>
                        <input class="form-control" style="width:100px;"  value="<?=$newsInfo['all_question_money']?>" <?php if($newsInfo['ispublish']):?>disabled="disabled"<?php endif;?>  id="all_question_money" type="text">
                    </div>
                    <div style="float: left;">
                        <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">活动截止时间<span style="color:red;">*</span>：</div>
                        <input class="form-control" style="width:100px;" type="text" placeholder="起始时间" id="activity_endtime" onClick="WdatePicker({minDate:'%y-%M-#{%d}'})" value="<?=$newsInfo['activity_endtime']?date("Y-m-d",$newsInfo['activity_endtime']):date("Y-m-d",time())?>" <?php if($newsInfo['ispublish']):?>disabled="disabled"<?php endif;?>>
                    </div>
                </div>
                <hr />
				<?php if($questionList):?>
                <?php foreach ($questionList as $key => $question):?>
                    <div class="row question_place">
                        <div class="col-md-8">
                            <label title="<?=$question['questionID']?>">Q<?=($key+1)?>：<?=$question['questionTitle']?>&nbsp;&nbsp;<i style="color:blue;"><?=$question['single_question_point']?>积分</i>&nbsp;&nbsp;<i style="color:blue;"><?=$question['single_question_money']?>元奖金</i></label>
                            
                            <?php if($question['questionType'] == 1):?>
                                <?php foreach ($question['option'] as $opkey => $option):?>
                                <div>
                                    <label>
                                        <input type="radio" name=""  <?php if($question['answer'] == ($opkey+1)):?>checked="checked"<?php else:?>disabled="disabled"<?php endif;?> />
                                        <?=$option['optionTitle']?>
                                    </label>
                                </div>
                                <?php endforeach;?>
                            <?php elseif ($question['questionType'] == 2):?>
                                <div>
                                <label>
                                    <input type="text" name="title" disabled="disabled"  class="form-control" value="<?=$question['answer']?>"><br />答案：<i style="color:green;"><?=$question['answer']?></i>
                                </label>
                                </div>
                            <?php elseif ($question['questionType'] == 3):?>
                                <div>
                                <label>
                                    <br />答案：<a href="<?= OSSHOST.$question['answer']?>" target="_blank"><img width="200" height="100" src="<?= OSSHOST.$question['answer']?>"></a>
                                </label>
                                </div>
                            <?php endif;?>
                            
                            <div class="horizontal-space"></div>
                        </div>
						<?php if($newsInfo['ispublish'] == 0):?>
                        <div>
                            <a  href="javascript:void(0);" data_id="<?=$question['questionID']?>" style="display: none"  class=" btn btn-danger pull-right js_del">删除 </a>
							<a  href="javascript:void(0);" data_id="<?=$question['questionID']?>" style="display: none"  class=" btn btn-default pull-right edit_question">编辑 </a>
                        </div>
						<?php endif;?>
                    </div>
                    <hr/>
                <?php endforeach;?>
				<div class="table-toolbar">
					<?php if($newsInfo['ispublish']):?>
					<button type="button" class="btn btn-palegreen" disabled="disabled">已发布</button>
					<?php else:?>
						<a id="js_publish" href="javascript:void(0);"  class="btn btn-palegreen">
							发布试题
						</a>						
					<?php endif;?>
					
				</div>
				<?php else:?>
				<div class="row" style="text-align:center;">暂时没有题目</div>
				<?php endif;?>
                </div>
            </div>
        </div>
<script src="<?= STATICURL; ?>js/jquery-2.0.3.min.js"></script>
<script src="<?= STATICURL; ?>js/bootstrap.min.js"></script>
<script src="<?= STATICURL; ?>layer/layer.js"></script>
<script src="<?php echo STATICURL; ?>js/wdatepicker/WdatePicker.js"></script>
<?php require_once ADMINVIEWPATH.'admin_footer.php'; ?>
<script>

$('.edit_question').on('click', function(){
        //iframe窗
        var questionID = $(this).attr("data_id");
		var id = "<?=$id?>";
        var title = "修改";
        if(questionID == undefined){
            questionID = "";
            title = "添加";
        }
        layer.open({
            type: 2,
            title: title,
            shade: [0.5, '#000'],
            shadeClose: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['550px', '360px'],
            content: '/luckydog/examination/editques?questionID='+questionID+"&id="+id
        });
    });
	$("#all_question_point").bind({
            keyup:function(){
                 var txt = $("#all_question_point").val();
                 var reg = /^[\d]+$/;
                 if(!reg.test(txt) ){
                        $(this).val('');
                 }
            },
            focus:function(){
                if ($(this).val() == 0){
                    $(this).val('');
                }
            },
            blur:function(){
                if ($(this).val() == ''){
                    $(this).val(default_order);
                }                   
            }
    }); 
    $("#all_question_money").bind({
            keyup:function(){
                 var txt = $("#all_question_money").val();
                 var reg = /^[\d]+$/;
                 if(!reg.test(txt) ){
                        $(this).val('');
                 }
            },
            focus:function(){
                if ($(this).val() == 0){
                    $(this).val('');
                }
            },
            blur:function(){
                if ($(this).val() == ''){
                    $(this).val(default_order);
                }                   
            }
    }); 
	$("#js_publish").click(function() {
    var id = "<?=$id?>";
    var activity_endtime = $("#activity_endtime").val();
    var all_question_point = $("#all_question_point").val();
    var all_question_money = $("#all_question_money").val();
    if(activity_endtime == "")
    {
        layer.msg("活动结束时间不能为空");
        return false;
    }
    var confirm_show = "发布试题后将不允许改动,请确认:\n"
                       +"全部答对时可获得积分："+all_question_point+"\n"
                       +"全部答对时可获得奖金："+all_question_money+"\n"
                       +"活动答题截止日期："+activity_endtime+"\n"
                       +"确定发布试题吗？";
    if (confirm(confirm_show)) {
        $.post("/luckydog/examination/publish", {"id":id,all_question_point:all_question_point,activity_endtime:activity_endtime,all_question_money:all_question_money}, function(res) {
            if (res) {
				layer.msg("发布成功");
               // window.location.reload();
            }else{
                layer.msg("发布失败");
            }
        });
    }
});
$(".js_del").click(function() {
    var id = $(this).attr("data_id");
    if (confirm("您确定要删除该吗？")) {
        $.post("/luckydog/examination/delete", {"id":id}, function(res) {
            if (res) {
                window.location.reload();
            }else{
                alert("删除失败");
            }
        });
    }
});


$(".js_reset").click(function() {
    var id = $(this).attr("data_id");
    if (confirm("删除设置将会清空所有选项，确定要删除吗")) {
        $.post("/luckydog/examination/reset", {"id":id}, function(res) {
            if (res) {
                window.location.reload();
            }else{
                alert("重置失败");
            }
        });
    }
});
$(".question_place").hover(function(){
    $(this).find(".js_del,.edit_question").show();
},function(){
    $(this).find(".js_del,.edit_question").hide();
});
    $(document).ready(function() {
        $(".it_province").change(function(){
            var privinceid = $(this).val();
            $.post("<?=BASEURL?>luckydog/news/cityList",{privinceid:privinceid},function(data){
                // console.log(data);
                var _option = '';
                $.each(data,function(index,item){
                    _option += '<option value="'+item.id+'">'+item.name+'</option>';
                });
                $(".it_city").html(_option);
            },'json');
        });
        
        $("#editNews").click(function(){
           
            var readonly = $(".readonly").prop("checked");
            if(readonly == true)
            {
                readonly = 1;
            }else{
                readonly = 0;
            }
            var cover = $(".uploadpic").attr("img-original");
            var title = $("input[name='title']").val();
            var point = $("input[name='point']").val();
            var transferfrom = $("input[name='transferfrom']").val();
            var id = $("#idpalce").val();
            var categoryid = $(".it_categoryid").val();
            var provinceid = $(".it_province").val();
            var cityid = $(".it_city").val();
            if(contents == ""){
                layer.msg("内容不能为空");return false;
            }
           
            if(transferfrom == ""){
                layer.msg("来源不能为空");return false;   
            }
            if(title == ""){
                layer.msg("标题不能为空");return false;   
            }
            if(categoryid == ""){
                layer.msg("新闻类型不能为空");return false;   
            }
            if(cityid == ""){
                layer.msg("请选择省市");return false;   
            }
           
        $.post("<?=BASEURL?>luckydog/news/editNews", {provinceid:provinceid,cityid:cityid,readonly:readonly, point:point,categoryid:categoryid,"contents":contents,"title":title,"transferfrom":transferfrom,"cover":cover,"id":id}, function(res) {
                if (res) {
                    layer.msg("成功");
                    window.location.href="/luckydog/news/index";
                }else{
                    layer.msg("失败");
                }
            });
        });
    });
</script>